﻿#ifndef PROTOCOLCONVERT_H
#define PROTOCOLCONVERT_H

#include <QObject>
#include <QSerialPort>

#include <QSerialPortInfo>
#include <QMap>
#include "../commons/comalgor.h"

/*
 *协议转化
*/

class ProtocolConvert : public QObject
{
    Q_OBJECT
public:
    explicit ProtocolConvert(QObject *parent = nullptr);
    virtual ~ProtocolConvert();

    static ProtocolConvert * gestance();


    void initComSeriel();


    void retCmdInfor(QByteArray infors);
    void findLevel(QMap<int ,int> maps);
    void lackMaterials(uint8_t cmda,uint8_t typs);
    void cleanCmdEnd(uint8_t cmda,int errors);
    void handlMixDeviceSuccess();

    void handlNotsupported(uint8_t cmda,uint8_t typs,uint8_t error = 0x04);

    //设备型号查询
    void handlDevices( uchar cmds ,QByteArray infors);
    void closeComSeriel();
    void openComSeriel();
signals:
    void sigFindLevel();
    void sigSequentialDischarge(uchar cmds, QByteArray infors);
    void sigSameDischarge( uchar cmds, QByteArray infors);
    void sigCleanIndex(uchar cmda,int indexs);
    void sigSolenoidValve( uchar cmds, QByteArray infors);
    void sigNotsupported( uchar cmds, QByteArray infors);
    void sigDevices( uchar cmds);
    void sigFindRuns( uchar cmds);
    void sigCloseValues( uchar cmds, QByteArray infors);

public slots:
    void onDataReceived();

private:

    static ProtocolConvert * m_protocolConvert;
    QSerialPort * m_serial;

    ComAlgor * m_comAlgor;
     QByteArray m_currentData ;
    uint16_t m_packageNumbers;
    uint8_t m_retCmd;
};

#endif // PROTOCOLCONVERT_H
